﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Windows.Forms;
using LumenWorks.Framework.IO.Csv;

namespace SVM_Sharp
{
    public partial class FormImportData : Form
    {
        public FormImportData()
        {
            InitializeComponent();
        }

        private const int MAX_SAMPLES = 5;

        private GroupBox m_gbCurrent;

        private void button1_Click(object sender, EventArgs e)
        {
            if (ofd_importar.ShowDialog() != DialogResult.OK)
                return;

            try
            {
                txtFileName.Text = ofd_importar.FileName;
                abrirStream();
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }

        private void abrirStream()
        {
            m_inputFile = File.OpenRead(txtFileName.Text);
            m_stream = readStream(m_inputFile);//readSampleStream(inputFile);
            preencherPreviewTexto(m_inputFile);
        }

        private void processarStream()
        {
            dgvOriginal.Rows.Clear();
            dgvOriginal.Columns.Clear();

            if (m_stream.Peek() == -1)
                m_stream = readStream(m_inputFile);//new StringReader(string.Join("\n", m_listaString.ToArray()));

            if (rdoDelimitado.Checked)
            {
                lerCSV(m_stream);
            }
            else if (rdoLarguraFixa.Checked)
            {
                lerLarguraFixa(m_stream);
            }
        }

        private StringReader readExample_0()
        {
            string ss = "M,0.455,0.365,0.095,0.514,0.2245,0.101,0.15,15\n" +
                        "M,0.35,0.265,0.09,0.2255,0.0995,0.0485,0.07,7\n" +
                        "F,0.53,0.42,0.135,0.677,0.2565,0.1415,0.21,9\n" +
                        "M,0.44,0.365,0.125,0.516,0.2155,0.114,0.155,10\n" +
                        "I,0.33,0.255,0.08,0.205,0.0895,0.0395,0.055,7\n" +
                        "I,0.425,0.3,0.095,0.3515,0.141,0.0775,0.12,8\n" +
                        "F,0.53,0.415,0.15,0.7775,0.237,0.1415,0.33,20\n";

            return new StringReader(ss);
        }

        private StringReader readExample_1()
        {
            string ss = "|1x3 Cross validator\n" +
                        "25, Private, 226802, 11th, 7, Never-married, Machine-op-inspct, Own-child, Black, Male, 0, 0, 40, United-States, <=50K.\n" +
                        "38, Private, 89814, HS-grad, 9, Married-civ-spouse, Farming-fishing, Husband, White, Male, 0, 0, 50, United-States, <=50K.\n" +
                        "28, Local-gov, 336951, Assoc-acdm, 12, Married-civ-spouse, Protective-serv, Husband, White, Male, 0, 0, 40, United-States, >50K.\n" +
                        "44, Private, 160323, Some-college, 10, Married-civ-spouse, Machine-op-inspct, Husband, Black, Male, 7688, 0, 40, United-States, >50K.\n" +
                        "18, ?, 103497, Some-college, 10, Never-married, ?, Own-child, White, Female, 0, 0, 30, United-States, <=50K.\n" +
                        "34, Private, 198693, 10th, 6, Never-married, Other-service, Not-in-family, White, Male, 0, 0, 30, United-States, <=50K.\n" +
                        "29, ?, 227026, HS-grad, 9, Never-married, ?, Unmarried, Black, Male, 0, 0, 40, United-States, <=50K.\n" +
                        "63, Self-emp-not-inc, 104626, Prof-school, 15, Married-civ-spouse, Prof-specialty, Husband, White, Male, 3103, 0, 32, United-States, >50K.\n" +
                        "24, Private, 369667, Some-college, 10, Never-married, Other-service, Unmarried, White, Female, 0, 0, 40, United-States, <=50K.\n";

            return new StringReader(ss);
        }

        private StringReader readExample_2()
        {
            string ss = @"75,-1,190,80,91,193,371,174,121,-16,13,64,-2,?,63,0,52,44,0,0,32,0,0,0,0,0,0,0,44,20,36,0,28,0,0,0,0,0,0,52,40,0,0,0,60,0,0,0,0,0,0,52,0,0,0,0,0,0,0,0,0,0,0,0,56,36,0,0,32,0,0,0,0,0,0,48,32,0,0,0,56,0,0,0,0,0,0,80,0,0,0,0,0,0,0,0,0,0,0,0,40,52,0,0,28,0,0,0,0,0,0,0,48,48,0,0,32,0,0,0,0,0,0,0,52,52,0,0,36,0,0,0,0,0,0,0,52,48,0,0,32,0,0,0,0,0,0,0,56,44,0,0,32,0,0,0,0,0,0,-0.2,0.0,6.1,-1.0,0.0,0.0,0.6,2.1,13.6,30.8,0.0,0.0,1.7,-1.0,0.6,0.0,1.3,1.5,3.7,14.5,0.1,-5.2,1.4,0.0,0.0,0.0,0.8,-0.6,-10.7,-15.6,0.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94,100,202,380,179,143,28,11,-5,20,?,71,0,72,20,0,0,48,0,0,0,0,0,0,0,64,36,0,0,36,0,0,0,0,0,0,20,52,48,0,0,56,0,0,0,0,0,0,64,32,0,0,0,72,0,0,0,0,0,0,0,60,12,0,0,44,0,0,0,0,0,0,0,60,44,0,0,32,0,0,0,0,0,0,56,0,0,0,0,0,0,0,0,0,0,0,0,40,44,0,0,20,0,0,0,0,0,0,0,52,40,0,0,32,0,0,0,0,0,0,0,56,48,0,0,36,0,0,0,0,0,0,0,60,48,0,0,36,0,0,0,0,0,0,0,64,40,0,0,40,0,0,0,0,0,0,0.9,0.0,7.8,-0.7,0.0,0.0,1.1,1.9,27.3,45.1,0.1,0.0,9.1,-2.6,0.0,0.0,0.4,1.5,24.5,36.8,-0.4,-0.4,1.6,-2.2,0.0,0.0,-1.0,-0.9,-1.5,-9.2,-0.4,-8.2,1.8,0.0,0.0,0.0,-0.7,-1.7,-23.4,-35.6,0.9,0.0,3.2,-0.4,0.0,0.0,0.7,1.2,9.4,18.0,-0.1,0.0,5.1,-2.5,0.0,0.0,0.3,0.6,9.8,12.6,1.6,-6.5,0.0,0.0,0.0,0.0,-0.4,-0.4,-18.2,-22.4,2.1,0.0,1.2,-6.9,0.0,0.0,-0.5,2.9,-12.7,18.0,0.7,0.0,9.0,-7.9,0.0,0.0,0.1,4.1,7.6,51.0,0.4,0.0,15.0,-5.5,0.0,0.0,0.1,3.3,28.8,63.1,0.1,0.0,15.2,-3.7,0.0,0.0,0.6,3.0,36.8,68.0,0.1,0.0,12.2,-2.2,0.0,0.0,0.4,2.6,34.6,61.6,1
75,0,190,80,88,181,360,177,103,-16,13,61,3,?,?,0,48,40,0,0,28,0,0,0,0,0,0,0,40,24,0,0,24,0,0,0,0,0,0,52,36,0,0,0,60,0,0,0,0,0,0,48,28,0,0,0,56,0,0,0,0,0,0,0,48,36,0,0,28,0,0,0,0,0,0,44,0,0,0,0,0,0,0,0,0,0,0,88,0,0,0,0,0,0,0,0,0,0,0,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16,0,0,0,0,0,0,0,60,0,0,0,32,0,0,0,0,0,0,0,24,36,32,0,68,0,0,0,0,0,0,0,36,44,0,0,20,0,0,0,0,0,0,0,40,48,0,0,24,0,0,0,0,0,0,0,56,40,0,0,40,0,0,0,0,0,0,0,52,36,0,0,32,0,0,0,0,0,0,20,44,36,0,0,44,0,0,0,0,0,0,-0.1,0.0,3.5,-2.0,0.0,0.0,0.4,1.3,3.7,13.5,0.0,0.0,9.9,-0.8,0.0,0.0,1.2,1.2,26.8,35.2,0.0,0.0,8.3,0.0,0.0,0.0,0.8,0.3,29.8,32.0,0.1,-6.1,1.1,0.0,0.0,0.0,-0.6,-1.2,-15.5,-24.1,0.0,0.0,0.6,-4.1,0.0,0.0,-0.1,0.8,-10.6,-4.9,-0.2,0.0,8.9,0.0,0.0,0.0,0.8,0.7,26.7,30.2,0.1,0.0,1.3,-5.4,1.9,0.0,0.2,0.8,-5.2,2.1,0.8,0.0,4.4,-8.5,0.0,0.0,0.8,3.9,-10.8,25.0,0.4,0.0,4.3,-7.3,0.0,0.0,1.1,4.0,-8.9,27.9,-0.5,0.0,7.0,-3.2,0.0,0.0,1.1,1.3,13.2,22.3,-0.5,0.0,10.9,-2.5,0.0,0.0,1.0,1.0,23.8,29.6,-0.5,-0.6,10.8,-1.7,0.0,0.0,0.8,0.9,20.1,25.1,10
62,0,170,72,102,135,401,156,83,72,71,68,72,?,70,20,36,48,0,0,36,0,0,0,0,0,0,0,52,0,0,0,28,0,0,0,0,0,0,0,104,0,0,0,36,0,0,0,0,0,0,40,36,0,0,0,48,0,0,0,0,0,0,28,24,40,0,0,40,0,0,0,0,0,0,0,84,0,0,0,28,0,0,0,0,0,0,0,24,64,0,0,12,0,0,0,0,0,0,20,16,56,0,0,28,0,0,0,0,0,0,24,28,52,0,0,40,0,0,0,0,0,0,24,32,56,0,0,40,0,0,0,0,0,0,20,36,56,0,0,40,0,0,0,0,0,0,20,40,52,0,0,40,0,0,0,0,0,0,-0.4,-0.5,5.8,-1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1,-0.2,0.0,8.2,-5.8,0.0,0.0,0.8,1.1,4.6,13.4,-0.3,0.0,7.1,-4.2,0.0,0.0,0.8,0.5,4.7,8.2,-0.2,0.0,6.3,-2.1,0.0,0.0,0.8,0.5,8.8,12.1,10
30,0,170,73,91,180,355,157,104,68,51,60,63,?,56,0,92,0,0,0,32,0,0,0,0,0,0,28,48,20,0,0,52,0,0,0,0,0,0,36,40,0,0,0,52,0,0,0,0,0,0,56,0,0,0,0,0,0,0,0,0,0,0,0,40,36,0,0,28,0,0,0,0,0,0,32,44,0,0,0,52,0,0,0,0,0,0,0,44,44,0,0,28,0,0,0,0,0,0,0,48,24,0,0,32,0,0,0,0,0,0,0,52,36,0,0,36,0,0,0,0,0,0,0,60,12,20,0,36,0,0,0,0,0,0,24,52,12,0,0,52,0,0,0,0,0,0,24,48,0,0,0,48,0,0,0,0,0,0,0.2,0.0,3.2,0.0,0.0,0.0,0.4,1.1,14.7,21.9,0.0,-1.3,14.6,-0.4,0.0,0.0,0.8,1.7,32.8,44.0,-0.1,-2.6,13.1,0.0,0.0,0.0,0.4,0.6,21.6,25.5,-0.1,-8.0,0.0,0.0,0.0,0.0,-0.6,-1.4,-22.4,-31.0,0.1,0.0,2.3,-5.7,0.0,0.0,-0.1,0.2,-5.6,-4.5,-0.1,-1.9,13.9,0.0,0.0,0.0,0.6,1.1,27.5,34.3,0.8,0.0,3.3,-7.4,0.0,0.0,0.2,-0.4,-9.0,-12.3,2.8,0.0,8.9,-8.0,0.0,0.0,0.3,1.3,11.7,22.6,1.5,0.0,11.4,-3.7,0.0,0.0,0.5,4.8,23.0,63.3,0.0,0.0,20.6,-2.6,0.8,0.0,0.6,5.4,61.1,103.2,-0.1,-1.1,19.0,-1.4,0.0,0.0,0.5,3.4,47.3,79.9,-0.6,-0.9,12.3,0.0,0.0,0.0,0.4,2.1,28.5,48.6,6
44,1,160,88,77,158,399,163,94,46,20,45,40,?,72,0,80,0,0,0,28,0,0,0,0,0,0,20,72,0,0,0,44,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4,1.1,18.4,28.9,1
40,1,153,55,82,140,388,149,82,52,17,105,42,?,68,0,80,0,0,0,40,0,0,0,0,0,0,0,52,28,0,0,32,0,0,0,0,0,0,20,40,32,0,0,44,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,28,28,0,0,0,36,0,0,0,0,0,0,0,52,24,0,0,32,0,0,0,0,0,0,0,24,48,0,0,12,0,0,0,0,0,0,0,28,44,0,0,16,0,0,0,0,0,0,0,40,40,0,0,24,0,0,0,0,0,0,0,48,40,0,0,28,0,0,0,0,0,0,0,52,36,0,0,32,0,0,0,0,0,0,0,52,0,0,0,28,0,0,0,0,0,0,-0.1,0.0,4.6,0.0,0.0,0.0,-0.2,1.9,18.4,31.7,-0.4,0.0,11.2,-0.9,0.0,0.0,0.8,1.6,27.9,39.1,-0.2,-0.5,6.5,-1.9,0.0,0.0,0.7,-0.5,9.5,6.6,0.1,-7.8,0.0,0.0,0.0,0.0,0.1,-1.6,-24.9,-35.4,-0.1,-1.0,1.5,0.0,0.0,0.0,-0.4,1.1,0.7,7.9,-0.1,0.0,8.9,-1.3,0.0,0.0,0.7,0.6,21.6,24.7,0.4,0.0,1.0,-10.4,0.0,0.0,0.0,-1.6,-23.7,-43.8,1.0,0.0,2.0,-10.7,0.0,0.0,0.0,1.0,-20.7,-8.1,0.8,0.0,4.4,-8.1,0.0,0.0,0.0,2.9,-7.4,29.1,-0.1,0.0,12.6,-4.9,0.0,0.0,0.6,1.9,20.4,37.1,-0.2,0.0,15.8,-2.9,0.0,0.0,0.5,2.5,35.8,57.8,-0.6,0.0,13.6,0.0,0.0,0.0,0.5,2.5,35.3,57.3,1
44,0,169,80,109,128,382,195,60,-34,112,154,7,?,63,20,80,0,0,0,44,0,0,0,0,0,0,0,52,68,0,0,36,0,0,0,0,0,0,0,28,76,0,0,16,0,0,0,0,0,0,76,0,0,0,0,0,0,0,0,0,0,0,24,76,0,0,0,56,0,0,0,0,0,0,0,44,60,0,0,20,0,0,0,0,0,0,76,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.4,15.1,1.3,0.0,1.2,-11.9,2.3,0.0,0.1,-2.2,-18.8,-38.6,1.2,0.0,2.6,-7.8,0.0,0.0,0.4,1.4,-12.5,0.1,-0.2,0.0,5.5,-3.6,0.0,0.0,0.6,3.8,11.2,45.4,0.1,0.0,11.6,-3.2,0.0,0.0,0.3,3.3,19.5,49.8,0.0,0.0,13.2,-2.3,0.0,0.0,0.4,3.5,25.2,57.4,0.0,0.0,12.7,-1.8,0.0,0.0,0.3,3.2,25.4,54.8,10";
            return new StringReader(ss);
        }

        private StringReader readExample()
        {
            string ss = @"    1        1      0.8590362064372231      0.9278245357602525      0.2528656223672442       0.298838311199668       0.1705212998954166       0.735936040913738      0.4283254278810799     0.5679469417703027      0.4743695999935477      0.2456748547110086      0.1042258652974851        0.8690907029810155      0.9975184956319734      0.4486200774528293       0.3075217871189428      0.8583103652138057      0.7969972396308247      0.8698930381357464         0
    1        2      0.6060410252371287      0.4577283627625244      0.3594484227670667      0.3069573767716065       0.8433307671777179      0.9348506611513181      0.4445724883608314     0.8280149253395697       0.296617752717187      0.6168699015410514      0.9757855814040846        0.9143436669954098      0.8452471419276359      0.8641518680676301       0.3467126889826937      0.3565734170881721      0.4384471887114665      0.5122561439056882         1
    1        3      0.9975997770308621      0.3732384871005909      0.5173993555298593      0.5049925456690189       0.6189033359884182      0.6055708232180527      0.7462253300408419     0.1959282919790389      0.8156669351065324      0.6793550279741694      0.8034130759821791        0.6439951609962413      0.7184411332114703       0.924775074027841       0.3153714063448004       0.250642370688729      0.2856355271897175      0.3658579636572136         1
    1        4      0.7834078593063168      0.1040553139561477      0.1975326951075759      0.4218371592474998       0.7420556675966105      0.4908278824153564    0.005525436956021521     0.3921232672136588     0.01001489496427692      0.4714626999390829      0.5978789030832963        0.7616587520758105      0.3627505607476147      0.9128190944424003       0.9779711752522013      0.8459212272518521      0.6994309323594078       0.475986734584957         1
    1        5      0.4062495307854584      0.5131992969299771     0.06181157701002021      0.6358367185561089       0.8447975169867277       0.441502226525659      0.1919264511554502     0.4875461161201303      0.3585335812259776      0.5515432350816102      0.7438765191563612        0.3123494343301799      0.6502228327173118      0.5222610158289576      0.04354476482710905      0.3766601113511974      0.2800977588864044      0.1322828760745728         1
    1        6     0.04137946970553862      0.6290259378832869      0.3033801053391976      0.8134075716681157       0.2228171225055121      0.9712060327589925      0.6097782897944045     0.6478038592160577      0.7379138729560913      0.4409432071131758     0.03598236603946942        0.6158676668988645     0.01748718426743936      0.9323195147599714       0.3293180378567842      0.9541227757917822      0.1353789149964642      0.2948047955455776         1
    1        7      0.1610500675703709       0.548838498016509      0.1535834560946872      0.6544153967846392       0.1403462127536639      0.7966458873060118      0.4058396236440684     0.6626356250127881     0.04942668516499301      0.5785194938329773      0.2648546829004772        0.9592173730462997      0.6981068318179394      0.4673589494441532       0.6370776960057103     0.01125133065377466      0.1473251569498744      0.2138142472223586         1
    1        8      0.4152989863935445      0.8987313634302053       0.931821763206325      0.9166479389325508       0.3991056376589566    0.009445114781717874      0.8462574603333551     0.6837725402619172      0.3973064568799197       0.886768087244127      0.5224278472764935        0.6947735654823999      0.8865223179739486      0.4116728830785077       0.4811080538564259      0.9265463702341853     0.02643087041538416     0.09273955239138255         1
    1        9      0.1667578778022693      0.3529718557178664      0.9881206108774576      0.2870703172960525       0.5636256000505657      0.4027078751797995       0.380931733126959     0.4791912380580066     0.06016529398038984      0.2365244451366986      0.2904837083330171        0.3918330724441653      0.2549443022593753      0.4883995859055884      0.05368356508487422      0.8622256041012912      0.4150551393809211      0.4871258994616154         1
    1       10      0.6556260785320773      0.4139307171921246       0.805288477992225      0.1634858637608381       0.8619016950781871      0.9475945318001323      0.5465636756814396     0.4261410062472957      0.4170803090984312      0.9456095739267767         0.3253875090068        0.6665268083633338      0.3742700553525032      0.1002913507425951       0.2132902799756266      0.2228596709539286    0.007286212501478278      0.4200273619990589         1
    1       11      0.5900079766417751      0.2936924123515686      0.4234978443942964      0.3298034631246183       0.4578376998568678      0.8297822964209547      0.4977667353853273     0.1594403342292127      0.9711218647438929      0.4923425384072794     0.08426897241087217        0.9743339475205478      0.9264239087209313      0.2954259188030847       0.8042124523444929      0.8708400092540413      0.5462950225350344      0.8848710788258662         1
    1       12      0.8819290793824216      0.4249161571807539      0.9032223669579252      0.1733059139094419         0.79100537164292      0.4761835240681346      0.6811758406900077     0.9058438524966025       0.828415465574815     0.08371732902273329      0.5205666508396261       0.07291534579255515      0.9480946850510211      0.9996158905262645       0.7284591146705983      0.2858883555836251      0.2108896425795845      0.8335898681530832         1
    1       13      0.9610102615228647      0.9769068064193965         0.8579287729834      0.6149712274976386       0.6155159288254153      0.3527692043429448      0.8339600060458502    0.09509174928146724      0.2308925419981177      0.9548332776512124      0.5771817487729197        0.7835114301751471      0.5304246445393397      0.1751697639960589       0.5444582641810283        0.08139244056462      0.7330148834657546      0.5313688547441011         0
    1       14      0.1725295253680088     0.01355637412958054      0.6234465078644765      0.5191358593020899       0.2544563627129214      0.3669473464549002     0.05569564438062824     0.5185014502805038       0.371256628975324      0.8537835646744093      0.3470398548421346        0.9473467321846532      0.5972810318745259      0.4288064848890322       0.4013699816578689      0.8204455701103951      0.5995842862887204      0.1356806756643992         1
    1       15      0.3965135587030091      0.2012412503025391      0.9681076397278553       0.836439981944083       0.6099766375923841      0.2446819819160737      0.7882705140250942      0.356016874864387      0.1250539998769657      0.5101025887829665      0.4039659679621562        0.8656119113425829      0.4995159909374909      0.5896484861215059      0.01499791595593302       0.893354827800714      0.5621224685054687     0.02844873743985469         1
    1       16     0.05162036324230333      0.3109125513402332      0.9092925575367796      0.7191174679254699        0.433167081923845      0.9971417491621752      0.2313817085918143     0.7715889360432306      0.5930693719975857       0.109138528102388      0.2151174598489888       0.05181928754835907      0.2935260403422743      0.7518454991811369       0.9224807585253277       0.606573033767442      0.3182088333984009      0.7188535135911984         1";
            return new StringReader(ss);
        }

        private StringReader readStream(FileStream inputFile)
        {
            /*
            return readExample();
            /*/
            StreamReader input = new StreamReader(inputFile);
            if (input == null)
                return null;
            return new StringReader(input.ReadToEnd());
            //*/
        }

        private StringReader readSampleStream(FileStream inputFile)
        {
            StreamReader input = new StreamReader(inputFile);
            StringReader sr = new StringReader(input.ReadToEnd());
            if (sr == null)
                return null;
            int iLinha = 1;
            int iInseridos = 0;
            m_listaString = new List<string>();
            string sLine;
            while ((sLine = sr.ReadLine()) != null)
            {
                if (++iLinha > nupLinhaInicio.Value)
                {
                    if (++iInseridos > MAX_SAMPLES)
                        break;

                    m_listaString.Add(sLine);
                }
            }
            return new StringReader(string.Join("\n", m_listaString.ToArray()));
        }

        private void lerLarguraFixa(StringReader sr)
        {
            int iRow = 0;
            int nChar = 0;
            int iCell = 0;
            int nCol = 0;
            int nTam = 0;
            try
            {
                string line;
                initDGV(ref dgvOriginal, dsLarguraFixa.Tables[0].Rows.Count, 1);
                while ((line = sr.ReadLine()) != null)
                {
                    iRow = dgvOriginal.Rows.Add();
                    nChar = 0;
                    iCell = 0;
                    foreach (DataRow linha in dsLarguraFixa.Tables[0].Rows)
                    {
                        nCol = (int)linha[0];
                        nTam = (int)linha[1];
                        string strCol = line.Substring(nChar, nTam);
                        nChar += nTam;
                        dgvOriginal.Rows[iRow].Cells[iCell++].Value = strCol;
                    }
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(string.Format("Erro ao processar arquivo com Largura Fixa - Linha({0}) Char({1}) Col({2})", iRow + 1, nChar, nCol));
            }
        }

        private void lerCSV(StringReader sr)
        {
            string strDelimiters = "";
            if (chkTab.Checked)
                strDelimiters += "\t";
            if (chkPoneVir.Checked)
                strDelimiters += ";";
            if (chkVirgula.Checked)
                strDelimiters += ",";
            if (chkEspaco.Checked)
                strDelimiters += " ";
            if (chkOutro.Checked)
                strDelimiters += txtOutro.Text;

            try
            {
                m_csv = new CachedCsvReader(sr, false, strDelimiters, txtQuote.Text, txtEscape.Text, txtComment.Text, ValueTrimmingOptions.All);

                initDGV(ref dgvOriginal, m_csv.FieldCount, 1);

                foreach (var linha in m_csv)
                {
                    int iRow = dgvOriginal.Rows.Add();
                    int iCell = 0;
                    foreach (var coluna in linha)
                    {
                        dgvOriginal.Rows[iRow].Cells[iCell++].Value = coluna;
                    }
                }
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return;
            }
        }

        private void preencherPreviewTexto(FileStream inputFile)
        {
            inputFile.Close();
            inputFile = File.OpenRead(txtFileName.Text);
            StreamReader input = new StreamReader(inputFile);
            txtPreview.Text = "";
            for (int i = 0; i < MAX_SAMPLES && input.Peek() > -1; ++i)
                txtPreview.Text += input.ReadLine() + Environment.NewLine;
            input.Close();

            //txtPreview.Text = readExample().ReadToEnd();
        }

        private void initDGV(ref DataGridView dgv, int _nCols, int offSet = 0)
        {
            dgv.Rows.Clear();
            dgv.Columns.Clear();

            for (int i = 0; i < _nCols; ++i)
            {
                dgv.Columns.Add(new DataGridViewTextBoxColumn());
                dgv.Columns[i].HeaderText = (i + offSet).ToString();
            }
        }

        private void checkBox5_CheckedChanged(object sender, EventArgs e)
        {
            txtOutro.Enabled = chkOutro.Checked;
        }

        private void preencheDictTexto(ref DataGridView dict)
        {
            int iCellClasse = obterPosicaoClasse();
            m_dict = new Dictionary<int, SortedSet<string>>();

            int total = dict.Rows.Count * 2;
            int parada = total / 100;
            int conta = 0;

            foreach (DataGridViewRow linha in dict.Rows)
            {
                if (++conta == parada)
                {
                    progressBar.PerformStep();
                    conta = 0;
                }

                if (linha.IsNewRow)
                    continue;
                int iCol = 0;
                foreach (DataGridViewCell coluna in linha.Cells)
                {
                    try
                    {
                        if (iCol == 0) //Coluna que usuario informou ser da classe
                            throw new System.Exception("class value.");

                        //tento dar parse para number, se não conseguir, deve ser texto
                        double d = double.Parse(coluna.Value.ToString(), System.Globalization.CultureInfo.InvariantCulture);
                    }
                    catch (System.Exception ex)
                    {
                        string texto = coluna.Value.ToString();
                        if (chkIgnoreCase.Checked)
                        {
                            texto = texto.ToLower();
                        }

                        if (!m_dict.ContainsKey(iCol))
                        {
                            m_dict.Add(iCol, new SortedSet<string>());
                        }

                        m_dict[iCol].Add(texto);
                    }
                    iCol++;
                }
            }

            preencherProcessaTexto();
        }

        private void verificarValorNumerico(ref DataGridViewCell rowCell, int iCol)
        {
            if (rowCell != null)
            {
                try
                {
                    double d = double.Parse(rowCell.Value.ToString(), System.Globalization.CultureInfo.InvariantCulture);
                }
                catch (System.Exception ex)
                {
                    string texto = rowCell.Value.ToString();
                    if (chkIgnoreCase.Checked)
                    {
                        texto = texto.ToLower();
                    }

                    if (!m_dict.ContainsKey(iCol))
                    {
                        m_dict.Add(iCol, new SortedSet<string>());
                    }

                    m_dict[iCol].Add(texto);
                }
            }
        }

        private CsvReader m_csv;
        private StringReader m_stream;
        private int m_nWizState = 0;
        private List<string> m_listaString;

        private void btnAdicionaColuna_Click(object sender, EventArgs e)
        {
            System.Data.DataRow tmprow = dsLarguraFixa.Tables[0].NewRow();
            tmprow[0] = dgvLarguraColunas.RowCount;
            tmprow[1] = nudTamanhoColuna.Value;
            dsLarguraFixa.Tables[0].Rows.Add(tmprow);
            lblColunaTamanho.Text = String.Format("Coluna {0} - Tamanho:", dgvLarguraColunas.RowCount);
        }

        private void preencherGridImportada()
        {
            try
            {
                int iCellClasse = obterPosicaoClasse();

                initDGV(ref dgvImportado, dgvOriginal.ColumnCount);

                dgvImportado.Columns[0].HeaderText = "Classe";

                int total = dgvOriginal.Rows.Count * 2;
                int parada = total / 100;
                int conta = 0;

                foreach (DataGridViewRow row in dgvOriginal.Rows)
                {
                    if (row.IsNewRow)
                        break;

                    if (++conta == parada)
                    {
                        progressBar.PerformStep();
                        conta = 0;
                    }

                    int j = 0;
                    int iRow = dgvImportado.Rows.Add();

                    for (j = 0; j < iCellClasse - 1; j++)
                    {
                        dgvImportado.Rows[iRow].Cells[j + 1].Value = obterValorProcessado(row.Cells[j]);
                    }

                    dgvImportado.Rows[iRow].Cells[0].Value = obterValorProcessado(row.Cells[j]);

                    for (j = iCellClasse; j < row.Cells.Count; j++)
                    {
                        dgvImportado.Rows[iRow].Cells[j].Value = obterValorProcessado(row.Cells[j]);
                    }
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }

        private int obterPosicaoClasse()
        {
            int iCellClasse = 0;
            if (rdoPosicaoClassePrimeira.Checked)
                iCellClasse = 0;
            else if (rdoPosicaoClasseUltima.Checked)
                iCellClasse = dgvOriginal.ColumnCount;
            else if (rdoPosicaoClasseOutra.Checked)
                iCellClasse = int.Parse(txtPosicaoClasseOutra.Text);
            return iCellClasse;
        }

        private string obterValorProcessado(DataGridViewCell dataGridViewCell)
        {
            bool bPassouParse = true;
            string textoCell = dataGridViewCell.Value.ToString();

            try
            {
                if (chkAtributoJuntoValor.Checked && txtAtributoSeparador.Text.Length > 0)
                {
                    List<char> lc = new List<char>();
                    lc.AddRange(txtAtributoSeparador.Text.ToString());
                    textoCell = textoCell.Split(lc.ToArray())[1];
                }
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            try
            {
                double d = double.Parse(textoCell);
                if (m_dict != null)
                {
                    if ((dataGridViewCell.ColumnIndex + 1) == obterPosicaoClasse() ||
                        (obterPosicaoClasse() == 0 && obterPosicaoClasse() == dataGridViewCell.ColumnIndex))
                    {
                        //if (d != -1.0 && d != +1.0)
                        {
                            throw new System.Exception("not valid class value.");
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                //throw new System.Exception(string.Format("Erro ao transformar valor em numérico Linha[{0}] Coluna[{1}]", iRow + 1, j + 1));
                System.Diagnostics.Debug.WriteLine(ex.Message);
                bPassouParse = false;
            }

            if (!bPassouParse)
            {
                try
                {
                    int nKey = dataGridViewCell.ColumnIndex;
                    if (obterPosicaoClasse() > nKey)
                        nKey++;
                    if (obterPosicaoClasse() == nKey)
                        nKey = 0;
                    if (m_dict != null && m_dict.ContainsKey(nKey))
                    {
                        string dataValue = dataGridViewCell.Value.ToString();

                        if (chkIgnoreCase.Checked)
                        {
                            dataValue = dataValue.ToLower();
                        }

                        foreach (DataGridViewRow row in dgvProcessaTexto.Rows)
                        {
                            string rowValue = row.Cells[0].Value.ToString();

                            if (chkIgnoreCase.Checked)
                            {
                                rowValue = rowValue.ToLower();
                            }

                            if (rowValue.Equals(dataValue) == false)
                                continue;

                            string tipo = row.Cells[1].Value.ToString();
                            if (tipo.Contains("Atributo"))
                            {
                                int nTipo = int.Parse(tipo.Split(' ')[1]);
                                if (nTipo == (nKey))
                                {
                                    double d = double.Parse(row.Cells[2].Value.ToString());
                                    return d.ToString();
                                }
                            }
                            else if (tipo.Contains("Classe"))
                            {
                                double d = double.Parse(row.Cells[2].Value.ToString());
                                return d.ToString();
                            }
                        }
                    }
                    if (!bPassouParse)
                        throw new System.Exception("erro");
                }
                catch (System.Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                    //throw ex;
                }
            }

            return textoCell.ToString();
        }

        private void chkAtributoJuntoValor_CheckedChanged(object sender, EventArgs e)
        {
            txtAtributoSeparador.Enabled = chkAtributoJuntoValor.Checked;
        }

        private void rdoPosicaoClasseOutra_CheckedChanged(object sender, EventArgs e)
        {
            txtPosicaoClasseOutra.Enabled = rdoPosicaoClasseOutra.Checked;
        }

        private void rdoDelimitado_CheckedChanged(object sender, EventArgs e)
        {
            chkTab.Enabled = rdoDelimitado.Checked;
            chkPoneVir.Enabled = rdoDelimitado.Checked;
            chkVirgula.Enabled = rdoDelimitado.Checked;
            chkEspaco.Enabled = rdoDelimitado.Checked;
            chkOutro.Enabled = rdoDelimitado.Checked;
            chkConsecutivos.Enabled = rdoDelimitado.Checked;
            txtQuote.Enabled = rdoDelimitado.Checked;
            txtEscape.Enabled = rdoDelimitado.Checked;
            txtComment.Enabled = rdoDelimitado.Checked;
            txtOutro.Enabled = rdoDelimitado.Checked;
        }

        private void rdoLarguraFixa_CheckedChanged(object sender, EventArgs e)
        {
            nudTamanhoColuna.Enabled = rdoLarguraFixa.Checked;
            dgvLarguraColunas.Enabled = rdoLarguraFixa.Checked;
            btnAdicionaColuna.Enabled = rdoLarguraFixa.Checked;
        }

        public Dictionary<int, SortedSet<string>> m_dict { get; set; }

        private void btProximo_Click(object sender, EventArgs e)
        {
            if (m_stream == null)
                abrirStream();

            switch (m_nWizState)
            {
                case 0:
                    {
                        processarStream();
                        if (dgvOriginal.ColumnCount < 2 || dgvOriginal.RowCount < 2)
                        {
                            progressBar.Visible = false;
                            m_gbCurrent = m_gbWiz0;
                            System.Windows.Forms.MessageBox.Show("Não foi possível processar o arquivo de forma válida com essa entrada! Altere os parâmetros.");
                            m_stream = null;
                            return;
                        }
                        m_gbCurrent = m_gbWiz1;
                        progressBar.Visible = true;
                        break;
                    }
                case 1:
                    {
                        progressBar.Value = 0;
                        m_dict = null;
                        preencherGridImportada();

                        bool bJaProcesou = false;

                        if (precisaProcessarTexto(bJaProcesou))
                        {
                            m_gbCurrent = m_gbWiz2;
                        }
                        else
                        {
                            m_nWizState++;
                            m_gbCurrent = m_gbWiz3;
                            btProximo.Enabled = false;
                        }

                        break;
                    }
                case 2:
                    {
                        progressBar.Value = 0;
                        preencherGridImportada();

                        bool bJaProcesou = true;

                        if (precisaProcessarTexto(bJaProcesou))
                        {
                            m_gbCurrent = m_gbWiz2;
                            System.Windows.Forms.MessageBox.Show("Erro passo 2");
                            return;
                        }
                        else
                        {
                            m_gbCurrent = m_gbWiz3;
                            btProximo.Enabled = false;
                        }

                        break;
                    }
            }
            button4.Enabled = true;
            m_nWizState++;

            esconderWizards();
            m_gbCurrent.Visible = true;
        }

        private bool precisaProcessarTexto(bool bJaProcessou)
        {
            preencheDictTexto(ref dgvImportado);
            if (bJaProcessou)
                return m_dict.Count > 1;

            if (m_dict.Count == 1)
            {
                if (m_dict.ContainsKey(0))
                {
                    SortedSet<string> dict_set = m_dict[0];
                    if (dict_set.Count == 2)
                    {
                        string[] array = new string[2];
                        dict_set.CopyTo(array);
                        try
                        {
                            bool classes_ready = (double.Parse(array[0]).Equals(-1) && double.Parse(array[1]).Equals(1)) ||
                                                           (double.Parse(array[0]).Equals(1) && double.Parse(array[1]).Equals(-1));
                            if (classes_ready)
                                return false;
                        }
                        catch (System.Exception ex) { }
                    }
                }
            }

            return m_dict.Count > 0;
        }

        private void esconderWizards()
        {
            m_gbWiz0.Visible = false;
            m_gbWiz1.Visible = false;
            m_gbWiz2.Visible = false;
            m_gbWiz3.Visible = false;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            switch (m_nWizState)
            {
                case 1:
                    {
                        button4.Enabled = false;
                        m_gbCurrent = m_gbWiz0;
                        progressBar.Visible = false;
                        break;
                    }
                case 2:
                    {
                        progressBar.Visible = true;
                        m_gbCurrent = m_gbWiz1;
                        break;
                    }

                case 3:
                    {
                        if (dgvProcessaTexto.RowCount < 2)
                        {
                            m_nWizState--;
                            m_gbCurrent = m_gbWiz1;
                        }
                        else
                            m_gbCurrent = m_gbWiz2;
                        break;
                    }
            }
            btProximo.Enabled = true;
            m_nWizState--;

            esconderWizards();
            m_gbCurrent.Visible = true;
        }

        private void FormImportData_Load(object sender, EventArgs e)
        {
            m_gbWiz1.Location = m_gbWiz0.Location;
            m_gbWiz2.Location = m_gbWiz0.Location;
            m_gbWiz3.Location = m_gbWiz0.Location;
            this.SetAutoSizeMode(AutoSizeMode.GrowAndShrink);
        }

        private void exportarArquivoLIBSVM()
        {
            SaveFileDialog sfd = new SaveFileDialog();
            string novoNome = ofd_importar.FileName.ToString();
            int iDotPos = novoNome.LastIndexOf('.');
            if (iDotPos == -1)
                iDotPos = novoNome.Length;
            novoNome = novoNome.Insert(iDotPos, "_LIBSVM");
            sfd.FileName = novoNome;
            if (sfd.ShowDialog() != DialogResult.OK)
                return;

            novoNome = sfd.FileName;
            System.IO.StreamWriter objWriter;
            objWriter = new System.IO.StreamWriter(novoNome);
            foreach (DataGridViewRow row in dgvImportado.Rows)
            {
                if (row.IsNewRow)
                    continue;
                StringWriter line = new StringWriter();
                int iCell = 0;
                foreach (DataGridViewCell cell in row.Cells)
                {
                    if (iCell == 0)
                    {
                        line.Write(cell.Value.ToString());
                    }
                    else
                    {
                        line.Write(" {0}:{1}", iCell, cell.Value);
                    }
                    iCell++;
                }
                objWriter.WriteLine(line);
            }
            objWriter.Close();

            System.Windows.Forms.MessageBox.Show("Arquivo gerado!");
        }

        private void btGerar_Click(object sender, EventArgs e)
        {
            exportarArquivoLIBSVM();
        }

        private void dgvProcessaTexto_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (dgvProcessaTexto.Rows[e.RowIndex].Cells[e.ColumnIndex - 1].Value.ToString().Contains("Classe") == true)
                    validarValorClasse(e);
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }

        private static bool tick = false;
        private FileStream m_inputFile;

        private void validarValorClasse(DataGridViewCellEventArgs e)
        {
            if (tick)
                return;

            tick = true;
            var editedCell = dgvProcessaTexto.Rows[e.RowIndex].Cells[e.ColumnIndex];
            var newValue = editedCell.Value;

            double d = double.Parse(editedCell.Value.ToString());
            if (d != -1.0 && d != +1.0)
            {
                editedCell.Value = "-1";
            }
            else
            {
                string other = (d * -1.0).ToString();

                for (int i = e.RowIndex - 1; i >= 0; i--)
                {
                    var reeditedCell = dgvProcessaTexto.Rows[i].Cells[e.ColumnIndex];
                    reeditedCell.Value = other;
                }

                try
                {
                    for (int i = e.RowIndex + 1; i < dgvProcessaTexto.RowCount - 1; i++)
                    {
                        if (dgvProcessaTexto.Rows[i].Cells[e.ColumnIndex - 1].Value.ToString().Contains("Classe") == false)
                            break;

                        var reeditedCell = dgvProcessaTexto.Rows[i].Cells[e.ColumnIndex];
                        reeditedCell.Value = other;
                    }
                }
                catch (System.Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            }
            tick = false;
        }

        private void preencherProcessaTexto()
        {
            dsProcessaTexto.Tables[0].Rows.Clear();
            int iCellClasse = 0;

            if (m_dict.ContainsKey(iCellClasse))
            {
                int nOnePosition = 0;
                SortedSet<string> values = m_dict[iCellClasse];
                foreach (var texto in values)
                {
                    DataRow iRow = dsProcessaTexto.Tables[0].NewRow();
                    iRow["Texto"] = texto;
                    iRow["Tipo"] = "Classe";
                    iRow["Numero"] = -1;
                    dsProcessaTexto.Tables[0].Rows.Add(iRow);
                    try
                    {
                        double d = double.Parse(texto);
                        if (d == 1.0)
                            nOnePosition = dsProcessaTexto.Tables[0].Rows.Count - 1;
                        else if (d == -1.0 && (nOnePosition == dsProcessaTexto.Tables[0].Rows.Count - 1))
                            nOnePosition = (nOnePosition + 1) % (values.Count);
                    }
                    catch (System.Exception) { }
                }

                if (dsProcessaTexto.Tables[0].Rows.Count > 1)
                    dsProcessaTexto.Tables[0].Rows[nOnePosition]["Numero"] = +1;
            }

            foreach (var lista in m_dict)
            {
                if (lista.Key == iCellClasse)
                    continue;

                string tipo = String.Format("Atributo {0}", lista.Key);
                int i = 0;
                foreach (var texto in lista.Value)
                {
                    DataRow iRow = dsProcessaTexto.Tables[0].NewRow();
                    iRow["Texto"] = texto;
                    iRow["Tipo"] = tipo;
                    iRow["Numero"] = i++;
                    dsProcessaTexto.Tables[0].Rows.Add(iRow);
                }
            }

            //dgvProcessaTexto.DataMember = dsProcessaTexto.Tables[0].TableName;
        }
    }
}